<template>
	<view class="navigation-bar-main" :style="{backgroundColor:bgColor}">
		<view class="navigation-placeholder">
			<view class="status_bar"></view>
			<view class="navigation-bar"></view>
		</view>
		<view class="navigation-content" :style="{position: fixed,backgroundColor:bgColor}">
			<view class="status_bar"></view>
			<view class="navigation-bar">
				<view class="left" @click="goBackAction" v-if="showGoBack">
					<span class="iconfont goback-icon" :style="{color:color}">&#xe603;</span>
				</view>
				<view class="center" v-if="!showSearch" :style="{color:color}">{{title}}</view>
				<view class="search-content" v-if="showSearch" @click="jumpSearchAction">
					<text class="iconfont search-icon">&#xe614;</text>
					<text class="search-text">请输入关键字搜索</text>
				</view>
				<view class="right"></view>
			</view>
		</view>
	</view>
</template>

<script lang="ts">
	import util from '@/static/js/util';
	export default {
		props: {
			title: {
				type: String,
				default: ""
			},
			showGoBack: {
				type: Boolean,
				default: true
			},
			showSearch: {
				type: Boolean,
				default: false
			},
			bgColor: {
				type: String,
				default: ""
			},
			color: {
				type: String,
				default: ""
			},
			fixed: {
				type: String,
				default: 'absolute'
			}
		},
		data() {
			return {};
		},
		methods: {
			goBackAction() {
				const _this: any = this
				if (_this.$listeners['goBack']) {
					_this.$emit("goBack");
					return
				}
				util.goBack()
			},
			jumpSearchAction() {
				util.jumpPage('/pages/search/search')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.navigation-bar-main {
		background-color: $navigation-bar-bg-color;
		z-index: 999;
		.navigation-content {
			width: 100%;
			top: 0;
			left: 0;
			z-index: 99;
		}
		.status_bar {
			height: var(--status-bar-height);
			width: 100%;
		}
		.navigation-bar {
			position: relative;
			height: 44px;
			
			display: flex;
		    align-items: center;
			.left {
				width: 40px;
				height: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
		
				.goback-icon {
					font-size: 15px;
					color: $navigation-text-color;
				}
			}
		
			.center {
				position: absolute;
				top: 0;
				left: 50%;
				transform: translateX(-50%);
				height: 100%;
				line-height: 44px;
				font-size: 16px;
				color: $navigation-text-color;
			}
			.search-content {
				display: flex;
				align-items: center;
				margin-right: 20rpx;
				width: 100%;
				height: 36px;
				background-color: #f2f2f7;
				border-radius: 28px;
				.search-icon {
					margin-left: 24rpx;
					margin-right: 16rpx;
					font-size: 36rpx;
					color: $base-text-color-grey;
				}
				.search-text {
					font-size: 28rpx;
					line-height: 28rpx;
					color: $base-text-color-grey;
				}
			}
		
			.right {
				position: absolute;
				top: 0;
				right: 0;
				height: 100%;
			}
		}
	}
</style>
